package ch.usi.inf.pf2.cell;

/**
 * The objects of this class contains the value of the cell if the user has
 * inserted some text
 * 
 * @author Lorenzo Baracchi
 */
public class Text extends Data {
	private String instance;

	/**
	 * Empty useless constructor
	 */
	public Text() {
		instance = "";
	}

	/**
	 * Create a Text object with the given instance
	 * 
	 * @param instance
	 *            the value for instance
	 * @return the new object
	 */
	public Text(String instance) {
		this.instance = instance;
	}

	/**
	 * Return a string representation of the Instance object
	 * 
	 * @retrun the string
	 */
	public String toString() {
		return instance;
	}

	/**
	 * Compare this Text to the given Data. The result is true only if d is an
	 * instance of Text, is not null and has the same value for the field as
	 * this.
	 * 
	 * @param d
	 *            the data to compare
	 * @return true if they are equals, false otherwise
	 */
	public boolean equals(Data d) {
		if (d == null)
			return false;
		else if (d instanceof Text)
			return equals((Text) d);
		else
			return false;
	}

	/**
	 * Compare this Text to the given Text. The result is true only if t is not
	 * null and has the same value for the field as this.
	 * 
	 * @param t
	 *            the data to compare
	 * @return true if they are equals, false otherwise
	 */
	public boolean equals(Text t) {
		if (t == null)
			return false;
		else
			return this.instance.equals(t.instance);
	}

	/**
	 * Return the instance value of the Text
	 * 
	 * @return the String representing the value
	 */
	public String getInstance() {
		return instance;
	}

	/**
	 * Set the instance value to the give parameter
	 * 
	 * @param instance
	 *            the new value
	 */
	public void setInstance(String instance) {
		this.instance = instance;
	}
}